/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import MODEL.Cargo;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Maratona
 */
public class DaoCargo extends Banco{
    
    public boolean insereCargo(Cargo cargo){
        try{
            Statement stm = Conecta().createStatement();
            String SQL = "INSERT INTO cargo VALUES(default,?)";
            PreparedStatement stmt = Conecta().prepareStatement(SQL);
            stmt.setString(1, cargo.getDescricao());
            stmt.execute();
            stmt.close();
        }catch(Exception e){
            
        }
        return false;
    }
    
    public Cargo getCargo(int cod_cargo){
        Cargo cargo = new Cargo();
        try{
            Statement stm = Conecta().createStatement();
            String SQL = "SELECT * FROM cargo WHERE cod_cargo="+cod_cargo;
            ResultSet rs = stm.executeQuery(SQL);
            while (rs.next()){
               cargo.setCodigo(cod_cargo);
               cargo.setDescricao(rs.getString("descricao"));
            }    
        }catch(Exception ex){
            
        }finally{
            Fecha();
        }
        return cargo;
    }
    public List<Cargo> getCargo(){
        List<Cargo> cargo = new ArrayList<>();
        try{
            Statement stm = Conecta().createStatement();
            String SQL = "SELECT * FROM cargo";
            ResultSet rs = stm.executeQuery(SQL);
            while (rs.next()){
                Cargo c = new Cargo();
               c.setCodigo(rs.getInt("cod_cargo"));
               c.setDescricao(rs.getString("descricao"));
               cargo.add(c);
            }    
        }catch(Exception ex){
            
        }finally{
            Fecha();
        }
        return cargo;
    }
}
